﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace BaddiesEditor
{
    public class TilePictureBox : PictureBox
    {
        /// <summary>
        /// Point in the father texture where we get our snippet from.
        /// </summary>
        private Point tilemapCoords;

        /// <summary>
        /// Handle to be called when the tile is clicked.
        /// </summary>
        private EventHandler tileClick;

        /// <summary>
        /// Gets the coordinate of the texture of this picture box in the 
        /// current loaded tilemap.
        /// </summary>
        public Point TilemapCoords
        {
            get { return this.tilemapCoords; }
        }

        /// <summary>
        /// Initializes a new instance of the TilePictureBox class.
        /// </summary>
        /// <param name="tileCoords">Point in the tilemap texture where this tile bitmap starts.</param>
        /// <param name="tileClick">Handler to call when the image is clicked.</param>
        public TilePictureBox(Point tileCoords, EventHandler tileClick)
            : base()
        {
            this.tilemapCoords = tileCoords;
            this.tileClick += tileClick;
        }

        /// <summary>
        /// Handles the event of the image being clicked.
        /// </summary>
        /// <param name="e">Arguments of the image click.</param>
        protected override void OnClick(EventArgs e)
        {
            TileClickArg arg = new TileClickArg();
            arg.TileBmp = new Bitmap(this.Image);

            this.tileClick(this, arg);
            base.OnClick(e);
        }
    }
}
